<?php
class CF_View_Template_Layout extends CF_View_Template
{
	/**
	 * @var string
	 */
	protected $_layoutPath = 'layouts/';
	
	/**
	 * 
	 * @var string
	 */
	protected $_scriptPath = 'scripts/';
	/**
	 * 
	 * @var string
	 */
	protected $_layout = null;
	
	/**
	 * 
	 * @var string
	 */
	protected $_script;
	
	/**
	 * 
	 * @var string
	 */
	protected $_includeScriptParamName = '__content';
	
	/**
	 * @var boolean
	 */
	protected $_renderLayout = true;
	
	/**
	 * @return string
	 */
	public function getLayoutPath()
	{
		return $this->_layoutPath;
	}
	
	/**
	 * 
	 * @param string $path
	 * @return string
	 */
	public function setLayoutPath($path)
	{
		$this->_layoutPath = $path;
		return $this;
	}
	
	/**
	 * @return string
	 */
	public function getScriptPath()
	{
		return $this->_scriptPath;
	}
	
	/**
	 * 
	 * @param string $path
	 * @return string
	 */
	public function setScriptPath($path)
	{
		$this->_scriptPath = $path;
		return $this;
	}
	
	/**
	 * @return string
	 */
	public function getLayout()
	{
		return $this->_layout;
	}
	
	/**
	 * 
	 * @param string $layout
	 * @return CF_View_Template_Layout $this
	 */
	public function setLayout($layout)
	{
		$this->_layout = $layout;
		return $this;
	}
	
	/**
	 * @return boolean
	 */
	public function getRenderLayout()
	{
		return $this->_renderLayout;
	}
	
	/**
	 * 
	 * @param boolean $bol
	 * @return CF_View_Template_Layout $this
	 */
	public function setRenderLayout($bol)
	{
		$this->_renderLayout = (boolean) $bol;
		return $this;
	}
	
	/**
	 * @return string
	 */
	public function getScript()
	{
		return $this->_script;	
	}
	
	/**
	 * 
	 * @param string $script
	 * @return CF_View_Template_Layout
	 */
	public function setScript($script)
	{
		$this->_script = $script;
		return $this;
	}
	
	/**
	 * 
	 * @param string $script
	 * @param string $layout [optional]
	 */
	public function render($script = null, $path = null)
	{
		if(null != $script) $this->setScript($script);
		
		$layout = $this->getLayout();
		$script = $this->getScript();
		
		if(null != $layout && $this->getRenderLayout()){
			$script = $this->_path . $this->_scriptPath . $script;
			$this->includeFile($this->_includeScriptParamName, $script . '.' . $this->getScriptExtension());
			return parent::render($layout, $this->_path . $this->_layoutPath);
		}
		return parent::render($script, $this->_path . $this->_scriptPath);
	}
}